import { IParam, EntityBase } from "@/core";
import { I{{pascalCase appEntity.codeName}} } from './interface/i-{{spinalCase appEntity.codeName}}';
import {{pascalCase appEntity.codeName}}Keys from './{{spinalCase appEntity.codeName}}-keys';

/**
 * {{appEntity.logicName}}基类
 * 基于template/src/api/\{{appEntities}}/\{{appEntities}}-base.ts.hbs生成  
 *
 * @export
 * @abstract
 * @class {{pascalCase appEntity.codeName}}Base
 * @extends { EntityBase }
 * @implements { I{{pascalCase appEntity.codeName}} }
 */
export abstract class {{pascalCase appEntity.codeName}}Base extends EntityBase implements I{{pascalCase appEntity.codeName}} {
	/**
	 * 实体名称
	 *
	 * @readonly
	 * @type {string}
	 * @memberof {{pascalCase appEntity.codeName}}Base
	 */
	get srfdename(): string {
		return '{{appEntity.name}}';
	}

	/**
     * 当前实体所有属性
     *
     * @protected
     * @type {string[]}
     * @memberof {{pascalCase appEntity.codeName}}Base
     */
    protected get keys(): string[] {
        return {{pascalCase appEntity.codeName}}Keys;
    }

	/**
	 * Creates an instance of ConstactOppoBase.
	 * @param {*} [data]
	 * @memberof {{pascalCase appEntity.codeName}}Base
	 */
	constructor(data?: any) {
		super();
		this.setData(data);
	}

{{#each appEntity.allPSAppDEFields as | field |}}
	{{#if field.keyField}}
	get srfkey(): string {
		return this.{{lowerCase field.codeName}};
	}

	set srfkey(val: string) {
		this.{{lowerCase field.codeName}} = val;
	}

	{{/if}}
	{{#if field.majorField}}
	get srfmajortext(): string {
		return this.{{lowerCase field.codeName}};
	}

	set srfmajortext(val: string) {
		this.{{lowerCase field.codeName}} = val;
	}
	{{/if}}
	/**
	 * {{field.logicName}}
	 **/
	{{lowerCase field.codeName}}?: any;
	
{{/each}}

	/**
	 * 重置实体数据
	 *
	 * @param {IParam} [data={}]
	 * @memberof {{pascalCase appEntity.codeName}}Base
	 */
	reset(data: IParam = {}): void {
		super.reset(data);
{{#each appEntity.allPSAppDEFields as | field |}}
	{{#if field.keyField}}
		this.{{lowerCase field.codeName}} = data.{{lowerCase field.codeName}} || data.srfkey;
	{{/if}}
	{{#if field.majorField}}
		this.{{lowerCase field.codeName}} = data.{{lowerCase field.codeName}} || data.srfmajortext;
	{{/if}}
{{/each}}
	}
}